package jobs

import (
	"cm2/exception"
	"cm2/service/task/tasks"
	"cm2/service/task/util"
)

// DeployWebSite 部署站点
type DeployWebSite struct {
	Job
}

// NewDeployWebSite 创建一个下载更新包任务执行器
func NewDeployWebSite() *DeployWebSite {
	tpkg := &DeployWebSite{}
	tpkg.SId = SIdPrefix("208CB42D-92A6-4449-9529-7D47B66110EF")
	tpkg.Code = "DeployWebSite"
	tpkg.Name = "部署网站"

	return tpkg
}

// InnerJob 获取内联的Job信息
func (tpkg *DeployWebSite) InnerJob() Job {
	return tpkg.Job
}

// ResolveJob 解析出单步任务清单
func (tpkg *DeployWebSite) ResolveJob(params map[string]interface{}) ([]tasks.Taskprovider, *exception.Exception) {
	ts := []tasks.Taskprovider{}
	// 模拟
	t1 := tasks.NewDownloader()
	t1.Serial = util.GenSerial(t1.SId)
	t1.Params = map[string]interface{}{
		"p1": 123,
		"p2": "http://xxxx/aaaa",
	}

	ts = append(ts, t1)

	t2 := tasks.NewUnzip()
	t2.Serial = util.GenSerial(t2.SId)
	t2.Params = map[string]interface{}{"p1": 453}

	ts = append(ts, t2)

	return ts, nil
}
